<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>全局配置</title>
        <meta name="csrf-token" content="{{ csrf_token() }}">
		@include('public.style')
	</head>
	<body>

		@include('public.navbar')

		<fieldset class="layui-elem-field layui-field-title" style="margin-top: 2rem;">
		  <legend>全局配置-------填写完记得点“立即提交”</legend>
		</fieldset>

		<form class="layui-form" action="" lay-filter="example">
		  <div class="layui-form-item">
		      <label class="layui-form-label">联盟ID</label>
		      <div class="layui-input-inline">
		        <input type="text" name="UnionId" lay-verify="required|number" placeholder="请输入你的联盟ID" autocomplete="off" class="layui-input">
		      </div>
			</div>

		  <div class="layui-inline">
		        <label class="layui-form-label">发单时间</label>
		        <div class="layui-input-inline">
		          <input type="text" class="layui-input" name="fd_time" lay-verify="required" id="test9" placeholder="每天的发单时间设置">
		        </div>
		  </div>



		  <div class="layui-form-item">
		    <label class="layui-form-label">发单开关</label>
		    <div class="layui-input-block">
		      <input type="checkbox" name="fd_close" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">
		    </div>
		  </div>

		  <div class="layui-form-item layui-form-text">
		    <label class="layui-form-label">新人进群欢迎语</label>
		    <div class="layui-input-block" style="width: 28rem;">
		      <textarea placeholder="请输入内容" style="height: 12rem;" class="layui-textarea" name="desc" lay-verify="required"></textarea>
		    </div>
		  </div>

		 <div class="layui-form-item">
		     <label class="layui-form-label">新人欢迎间隔时间</label>
		     <div class="layui-input-inline" style="width: 7rem;">
		       <input type="text" name="at_time" lay-verify="required|number" placeholder="请输入整数" autocomplete="off" class="layui-input">
		     </div>
			 <div class="layui-form-mid layui-word-aux">分钟</div>
		</div>

		<div class="layui-form-item">
		     <label class="layui-form-label">商品间隔时间</label>
		     <div class="layui-input-inline" style="width: 7rem;">
		       <input type="text" name="goods_rest" lay-verify="required|number" placeholder="请输入整数" autocomplete="off" class="layui-input">
		     </div>
			 <div class="layui-form-mid layui-word-aux">分钟，发送一个商品后休息多少分钟后再发送下一个商品</div>
		</div>

		<div class="layui-form-item">
		     <label class="layui-form-label">图片间隔时间</label>
		     <div class="layui-input-inline" style="width: 7rem;">
		       <input type="text" name="img_rest" lay-verify="required|number" placeholder="请输入整数" autocomplete="off" class="layui-input">
		     </div>
			 <div class="layui-form-mid layui-word-aux">秒，发送图片后休息多少秒再发送文案</div>
		</div>

		  <div class="layui-form-item">
		    <div class="layui-input-block">
		      <button type="button" class="layui-btn layui-btn-normal" id="LAY-component-form-setval">默认配置</button>
		      <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
		    </div>
		  </div>
		</form>

		@include('public.script')
		<script>
		// var data1 = get_qj_config();//获取配置
        var data1 = '';
        $.ajax({
                    async : false,
                    type: "post",
                    url: "/user/get_qj_config",
                    contentType:'application/json;charset=UTF-8',
                    headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                    error : function(request) {
        					  layer.msg("error");
                    },
                    success : function(data) {
                        // alert(data.goods_rest);
                        data1 = data;
                    }
                });
                console.log(data1);
		layui.use(['form', 'layedit', 'laydate'], function(){
		  var form = layui.form
		  ,layer = layui.layer
		  ,layedit = layui.layedit
		  ,laydate = layui.laydate;


			form.val('example', {
			  "UnionId": data1.UnionId // "name": "value"
			  ,"fd_time": data1.start_time + " - " + data1.end_time
			  // ,"close": (data1.fd_status = 1 ? true : false) //开关状态,发单状态,0关，1开
			  // ,"fd_close": true //开关状态,发单状态,0关，1开
			  ,"fd_close": (data1.fd_status == 1 ? true : false) //开关状态,发单状态,0关，1开
			  ,"desc": (data1.room_desc == null ? "" : Base64.decode(data1.room_desc))
			  ,"at_time": data1.at_time
			  ,"goods_rest": data1.goods_rest
			  ,"img_rest": data1.img_rest
			});

			//自定义验证规则
			  form.verify({
			    title: function(value){
			      if(value.length < 5){
			        return '标题至少得5个字符啊';
			      }
			    }
			    ,pass: [
			      /^[\S]{6,12}$/
			      ,'密码必须6到12位，且不能出现空格'
			    ]
			    ,content: function(value){
			      layedit.sync(editIndex);
			    }
			  });

		  //监听指定开关
		  form.on('switch(switchTest)', function(data){
		    // layer.msg('开关checked：'+ (this.checked ? 'true' : 'false'), {
		    //   offset: '6px'
		    // });
		    layer.tips('发单状态：'+ (this.checked ? '开' : '关'), data.othis)
		  });

		  //监听提交
		  form.on('submit(demo1)', function(data){
		    // layer.alert(JSON.stringify(data.field), {
		    //   title: '最终的提交信息'
		    // }),
			// console.log(data.field);
			$.ajax({
			            async : false,
			            type: "post",
			            url: "/user/write_config",
			            contentType:'application/json;charset=UTF-8',//更新配置
			            data: JSON.stringify(data.field),
			            headers: {
			                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			                },
                        error : function(request) {
								  layer.msg("error");
			            },
			            success : function(data) {
			                // alert(data.code);
								  if(data.code == 0){
									  layer.msg("更新配置成功！")
								  }else{
									  layer.msg("error:"+data.msg)
								  }
			            }
			        });
		    return false;
		  });


		  //表单赋值
		  layui.$('#LAY-component-form-setval').on('click', function(){
		    form.val('example', {
		      "username": "1000111000" // "name": "value"
		      ,"fd_time": "09:00:00 - 21:00:00"
		      // ,"fd_close": true //开关状态
		      ,"fd_close": true //开关状态
		      ,"at_time": "10" //开关状态
		      ,"goods_rest": "10" //商品间隔时间
		      ,"img_rest": "7" //图片间隔时间
		      ,"desc": "你好，[成员昵称]\n 欢迎来到👏 [群名] ～\n请您花1分钟了解一下\n【群规】：\n 1）群主每天为家人们发送JD好物商品；\n 2）亲友们如果有指定商品类型可以@ 群主，群主会想办法为大家找优惠商品；\n 3）如果您觉得信息打扰正常工作，可以点击群右上角设置为【消息免打扰】，但是强烈建议设置为【置顶聊天】，让优惠信息更醒目；\n 4）同时也恳请各位亲友不要乱发广告和无用信息，维护好咱们自己的群，做相亲相爱的一家人。"
		    });
		  });

		});
		</script>
		<script>
		layui.use('laydate', function(){
		  var laydate = layui.laydate;

		  //时间范围
		  laydate.render({
		    elem: '#test9'
		    ,type: 'time'
		    ,range: true
		  });

		});
		</script>
	</body>
</html>
